Fix: internal error caused by the generic type alias with an unpacked list #20689
Fix: internal error caused by the generic type alias with an unpacked list #20689ilevkivskyi merged 28 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
Updated type alias test cases to reflect syntax changes.
This comment has been minimized.
This comment has been minimized.
Update error messages for invalid syntax in type alias tests.
This comment has been minimized.
This comment has been minimized.
Add tests for type alias unpacking with lists.
This comment has been minimized.
This comment has been minimized.
Update type alias tests to reflect unpacking errors for list[int].
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
left a comment
There was a problem hiding this comment.
Not a full review, just something for you while you are fixing the tests.
| unpacked = get_proper_type(item.type) | ||
| if isinstance(unpacked, Instance): | ||
| assert unpacked.type.fullname == "builtins.tuple" | ||
| if unpacked.type.fullname != "builtins.tuple": |
There was a problem hiding this comment.
Please add a comment above this line explaining that expand_type() may be called during semantic analysis, before invalid unpacks are fixed.
This comment has been minimized.
This comment has been minimized.
Add comment to clarify behavior during semantic analysis.
This comment has been minimized.
This comment has been minimized.
Updated test cases for TypeAlias unpacking in Python.
This comment has been minimized.
This comment has been minimized.
Removed xfail marker from test case and updated comments for clarity.
This comment has been minimized.
This comment has been minimized.
Add test cases for unpacked type aliases in Python 3.10 and 3.11
This comment has been minimized.
This comment has been minimized.
Update error messages for type alias unpacking tests.
This comment has been minimized.
This comment has been minimized.
Update error messages for unpacking list in type alias tests to reflect Python version requirements.
Updated error messages for unpacking list[int] in type alias tests.
This comment has been minimized.
This comment has been minimized.
Updated type alias test cases to reflect syntax changes in Python 3.11.
Updated test cases to reflect unpacking rules for TypeAlias.
This comment has been minimized.
This comment has been minimized.
Update comments to clarify expectations for unpacking lists in type aliases.
This comment has been minimized.
This comment has been minimized.
|
|
||
| # Only "Test suite with py310-ubuntu, mypyc-compiled" expects: Invalid syntax | ||
| # The other tests expect: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) | ||
| # v1: TA[*list[int]] |
There was a problem hiding this comment.
If you want to test the new *-syntax, you should move the test to check-python311.test, then you will not need all these dances with having two separate tests, etc.
There was a problem hiding this comment.
I cannot write the tests for the code v1: TA[*list[int]] which produces 3 kinds of error through different Python versions and tests.
For v1: TA[*list[int]] :
-
Python 3.10 with only "Test suite with py310-ubuntu, mypyc-compiled" produces:
error: Invalid syntax
-
Python 3.11 with only "Test suite with py310-ubuntu, mypyc-compiled" produces:
error: Invalid syntax; you likely need to run mypy using Python 3.11 or newer
-
Python 3.10 and Python 3.11 with the other tests produce:
error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple)
There was a problem hiding this comment.
It is less tricky if you follow advise precisely :-)
Remove tests for unpacking type aliases in Python 3.10 and 3.11.
Removed test cases related to TypeAlias unpacking for tuples.
Remove test case for unpacked tuple with TypeAlias
Add test cases for unpacking TypeAlias with TypeVarTuple in Python 3.10 and 3.11.
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fix: #20549